const globalIp = getApp().globalData.userIp
Page({

  /**
   * 页面的初始数据
   */
  data: {
    screen:"产品类型",
    screenEng: "",
    screenDown: {screenDown:["成品CP","样品YP"],screen:0},
    screenFlag: false,//控制综合下拉框是否显示
    screenColor: false,
    dataColor: false,
    dataTime:"日期选择",
    dataTime1:"起始日期",
    dataTime2:"截止日期",
    data1:getApp().globalData.nowTime,
    data2:getApp().globalData.nowTime,
    type:"",
    dataFlag: false, //控制综合下拉框是否显示
    status: false,
    nowTime: getApp().globalData.nowTime,
    list:[],
    cardCode: ''
  },

  screenShow: function () {//综合下拉
    if (this.data.screenFlag){
      this.setData({
        screenFlag : !this.data.screenFlag,
        dataFlag: false,
        dataColor: false
      })
    }else{
      this.setData({
        screenFlag: !this.data.screenFlag,
        dataFlag: false,
        dataColor: false
      })
    }
  },

  dataShow: function () {//日期下拉
    if (this.data.dataFlag){
      this.setData({
        dataFlag : !this.data.dataFlag,
        screenFlag: false,
        screenColor: false
      })
    }else{
      this.setData({
        dataFlag: !this.data.dataFlag,
        screenFlag: false,
        screenColor: false
      })
    }
  },

  screenChoice:function(e){//综合下拉选择子项
    var screenEng = "";
    switch(e.currentTarget.dataset.index) {
      case 0: screenEng = "CP";break;
      case 1: screenEng = "YP";break;
    }
    this.setData({
      screen: e.currentTarget.dataset.item,
      screenEng: screenEng,
      "screenDown.screen": e.currentTarget.dataset.index,
      screenFlag: false,
      screenColor: true,
    })
    this.getManage()
  },

  handletouchtart: function (event) {//点击透明背景隐藏下拉
    this.setData({
      screenFlag: false,
      dataFlag: false
    })
  },

  changeDate1(e) {
    console.log(e)
    this.setData({
      dataTime1: e.detail.value,
      dataFlag: false,
      dataColor: true
    })
    this.getManage()
  },
  changeDate2(e) {
    this.setData({
      dataTime2: e.detail.value,
      dataFlag: false,
      dataColor: true,
    })
    this.getManage()
  },

  getManage: function() {
    let that = this;
    wx.showLoading({
      title: '计算中，请等待',
      mask: true
    })
    wx.request({
      url: globalIp + 'home/oitm/selAftReserve',
      data: {
        // value: that.data.screenEng || "CP",
        sdate: that.data.dataTime1 == '起始日期' ? '' : that.data.dataTime1,
        openId: wx.getStorageSync('userInfo').openid,
        lineNum: '1',
        pageIndex: 0,
        cardCode: that.data.cardCode
      },
      header: {
        'content-type': 'application/json'
      },
      method: 'POST',
      success: function(res) {
        if (res.data.jsonObject) {
          var data = res.data.jsonObject.data;
          console.log(data)
          if (data.length>0) {
            that.setData({
              list: data,
              status: false,
              date1: that.data.dataTime1 == '起始日期' ? '' : that.data.dataTime1,
            })
          } else {
            that.setData({
              list: [],
              status: true,
              date1: that.data.dataTime1 == '起始日期' ? '' : that.data.dataTime1,
            })
          }
        }
      },
      fail: function(res) {
        wx.showToast({
          title: '请返回上一页面，重新请求',
          icon: 'none',
          duration: 2000,
        })
      },
      complete: function(res) {
        wx.hideLoading()
      }
    })
  },

  gridBtn: function(e) {
    wx.navigateTo({
      url: './aftindex/aftindex?type='+e.currentTarget.dataset.whscode+'&sdate='+this.data.date1+'&cardCode='+(this.data.cardCode || ''),
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      cardCode: options.cardCode
    })
    this.getManage()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    
  },

}) 